package org.alps.pattern.factory.simplefactory;

import org.alps.pattern.factory.ICourse;
import org.alps.pattern.factory.JavaCourse;

/**
 * 课程工厂
 * @date 2021-04-26
 * @author zkw
 */
public class CourseFactory {

    /**
     * 创建课程
     * @param name
     * @return
     */
    public ICourse create(String name) {
        if ("java".equalsIgnoreCase(name)) {
            return new JavaCourse();
        } else {
            return null;
        }
    }

    public ICourse create(Class clazz) {
        try {
            if (clazz != null) {
                ICourse course = (ICourse) clazz.newInstance();
                return course;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
